package com.doyoo.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.doyoo.enums.Type;
import io.swagger.annotations.ApiModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 定时任务-步骤模板
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "JobStepTemplate对象", description = "定时任务-步骤模板")
public class JobStepTemplate implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "自增id")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @NotEmpty(message = "'name'不能为空")
    @Schema(description = "定时任务步骤模板名称")
    private String name;

    @NotNull(message = "'type'不能为空")
    @Schema(description = "类型，1 shell，2 python")
    private Type type;

    @NotEmpty(message = "'script'不能为空")
    @Schema(description = "脚本模板")
    private String script;

    @NotEmpty(message = "'parameter'不能为空")
    @Schema(description = "脚本模板中的参数值, JSON格式")
    private String parameter;

    @TableLogic   //逻辑删除, 使用delete方法时不会物理删除
    @TableField(insertStrategy = FieldStrategy.NEVER, select = false) // SQL插入忽略此值
@Schema(description = "状态，0正常，1删除")
    private Integer state;

@Schema(description = "创建时间")
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime createTime;

@Schema(description = "更新时间")
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime updateTime;

    public String getTypeName() {
        for (Type e : Type.values()) {
            if (e.equals(this.getType())) {
                return e.getName();
            }
        }
        return null;
    }
}
